// pages/music/music.js
const http=require('../../models/http')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    musics:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (options) {
    var hot=await http.getHot();
    var japan=await http.getJapan();
    var radio=await http.getRadio();
    console.log(hot,japan,radio)
    var musics=[];
    var hotMusic={};
    var japenMusic={};
    var radios={};
    hotMusic.title="热门音乐";
    hotMusic.titlePic="https://i.loli.net/2019/10/23/a96TOiYrA1jQzvf.png";
    japenMusic.title="日乐";
    japenMusic.titlePic="https://i.loli.net/2019/10/23/B1Jg7W2zYRkLHjw.png";
    radios.title="主播电台";
    radios.titlePic="https://i.loli.net/2019/10/23/sR6FP4YbOitEg51.png";
    var hotData=[];
    await this.bianliA(hot.data.playlists,hotData);
    var japenData=[];
    await this.bianliA(japan.data.playlists,japenData);
    var radioData=[];
    await this.bianliB(radio.data.result,radioData);
    wx.setStorageSync("hotMusic",hotData);
    wx.setStorageSync("japenMusic",japenData);
    wx.setStorageSync("radioData",radioData);
      
    hotMusic.data=hotData.slice(0,3);
    japenMusic.data=japenData.slice(0,3);
    radios.data=radioData.slice(0,3);
    musics.push(hotMusic);
    musics.push(japenMusic);
    musics.push(radios);
    this.setData({
      musics
    })
    console.log(musics)
  },
  bianliA:function (arrA,arrB){//将A的部分数据给B
    arrA.forEach(item=>{
      var obj={};
      obj.Pic=item.coverImgUrl;
      obj.title=item.name;
      obj.id=item.id;
      obj.people=item.playCount;
      obj.other=item.description;
      arrB.push(obj);
      
    })
    return arrB;
  },
  bianliB:function (arrA,arrB){//将A的部分数据给B
    arrA.forEach(item=>{
      var obj={};
      obj.Pic=item.picUrl;
      obj.title=item.copywriter;
      obj.id=item.id;
      obj.other=item.name;
      arrB.push(obj);
    })
    return arrB;
  }
})